package ObserverModel2;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lenovo on 2017/5/15.
 */
public abstract class Subject {

    private List<Observer> list = new ArrayList<>();

    /**
     * 订阅
     *
     * @param observer
     */
    public void Attach(Observer observer) {
        list.add(observer);
    }

    /**
     * 撤销订阅
     *
     * @param observer
     */
    public void Detach(Observer observer) {
        list.remove(observer);
    }

    /**
     * 通知
     */
    public void Notify() {
        System.out.println("Update:");

        for (Observer observer : list) {
            observer.Update();
        }
    }
}
